package com.flux.ui.adapter

import android.content.Intent
import android.support.annotation.LayoutRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.flux.ui.fragment.FBaseFragment
import java.lang.ref.WeakReference

/**
 * 用于Fragment的RecycleAdapter
 * Created on 2017/12/28.
 *
 * @author yang
 */
abstract class FFragmentRecycleAdapter(var mFragment: WeakReference<FBaseFragment>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    protected fun startActivity(intent: Intent) {
        mFragment.get()?.startActivity(intent)
    }

    protected fun startActivity(cls: Class<*>, vararg extras: String) {
        mFragment.get()?.startActivity(cls, *extras)
    }

    protected fun startActivityForResult(cls: Class<*>, requestCode: Int, vararg extras: String) {
        mFragment.get()?.startActivityForResult(cls, requestCode, *extras)
    }

    protected fun getRes() = mFragment.get()?.context?.resources


    protected fun getItemView(@LayoutRes layout: Int, parent: ViewGroup) = LayoutInflater.from(mFragment.get()?.context).inflate(layout, parent, false)!!
}